<%@ Page Language="C#" %>
<%@ Import Namespace="SoftwareMonkeys.Scriptech.Web" %>
<%@ Import Namespace="SoftwareMonkeys.Scriptech.Scripts" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web" %>
<%@ Register Namespace="SoftwareMonkeys.Scriptech.Web" Assembly="SoftwareMonkeys.Scriptech.Web" TagPrefix="cc" %>
<script runat="server">
	protected string ScriptControlPath = String.Empty;
	protected string ScriptName = String.Empty;
	
	protected override void OnLoad(EventArgs e)
	{
		//ScriptForm.Action = Request.Url.ToString();
	
		ScriptName = Request.QueryString["Script"];
				
		string shortName = ScriptName;
		
		if (ScriptName.IndexOf("?") > -1)
			shortName = ScriptName.Substring(0, ScriptName.IndexOf("?"));				
				
		if (Path.GetExtension(ScriptName).Trim('.') == "script")
			ScriptControlPath = GetScriptletPath(shortName);
		else
			ScriptControlPath = GetScriptPath(shortName);
			
		Control control = LoadScriptControl(ScriptControlPath);
	
		ScriptHolder.Controls.Add(control);
		
		base.OnLoad(e);
	}
	
	protected Control LoadScriptControl(string scriptControlPath)
	{
		Control control = Page.LoadControl(ScriptControlPath);
		
		return control;
	}

	string GetScriptPath (string scriptName)
	{
		string scriptsDirectory = "~/Scripts";
		
		string scriptPath = scriptsDirectory + Path.DirectorySeparatorChar + scriptName;
		
		return scriptPath;
		
	}

	string GetScriptletPath (string scriptName)
	{
		string scriptsDirectory = "~/Scripts";
		
		string scriptPath = scriptsDirectory + Path.DirectorySeparatorChar + scriptName;
		
		string newScriptPath = ScriptLauncher.GetPreparedScriptletPath(scriptName, scriptPath);
		
		return newScriptPath;
	}

	
</script><asp:placeholder runat="server" id="ScriptHolder"/>
